﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Tasks;

namespace Groovy_IM
{
    public partial class SettingsPage : PhoneApplicationPage
    {
        public SettingsPage()
        {
            InitializeComponent();

            App.systemTrayBar(App.SystemTrayIsVisible);

            if (App.Orientation == SupportedPageOrientation.PortraitOrLandscape)
                Landscape.IsChecked = true;

            SupportedOrientations = App.Orientation;

            runLocked.IsChecked = App.runLocked;

            SystemTrayBarSwitch.IsChecked = App.SystemTrayIsVisible;

            confirmExit.IsChecked = App.confirmExit;
        }

        private void PhoneApplicationPage_OrientationChanged(object sender, OrientationChangedEventArgs e)
        {
            if ((e.Orientation & PageOrientation.Portrait) == (PageOrientation.Portrait))
            {
                abWidth.Width = 455;
                appWidth.Width = 455;
                buddyWidth.Width = 455;
                msgWidth.Width = 455;
                tellFriend.Width = 455;
                facebook.Width = 235;
                twitter.Width = 235;
            }
            else
            {
                abWidth.Width = 775;
                appWidth.Width = 775;
                buddyWidth.Width = 775;
                msgWidth.Width = 455;
                tellFriend.Width = 775;
                facebook.Width = 385;
                twitter.Width = 385;
            }
        }

        private void SystemTrayBarSwitch_Checked(object sender, RoutedEventArgs e)
        {
            App.systemTrayBar(true);
        }

        private void SystemTrayBarSwitch_Unchecked(object sender, RoutedEventArgs e)
        {
            App.systemTrayBar(false);
        }

        private void Landscape_Checked(object sender, RoutedEventArgs e)
        {
            App.Orientation = SupportedPageOrientation.PortraitOrLandscape;

            this.SupportedOrientations = App.Orientation;
        }

        private void Landscape_Unchecked(object sender, RoutedEventArgs e)
        {
            App.Orientation = SupportedPageOrientation.Portrait;

            this.SupportedOrientations = App.Orientation;
        }

        private void Button_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            string Tag = (sender as Button).Tag.ToString();
            
            WebBrowserTask wbt = new WebBrowserTask();

            switch (Tag)
            {
                case "0":
                    EmailComposeTask emailTask = new EmailComposeTask();
                    emailTask.Subject = "Check out Groovy IM!";
                    emailTask.Body = "Hey,\n\nI think you should check out Groovy IM on your Windows Phone " +
                        "7 Device.\n\nGroovy IM is a Windows Phone 7 Messaging Application " +
                        "that allows you to join group chats, send messages to your friends, and " +
                        "meet new people over the phone within minutes, using services such as Groovy, " +
                        "AIM, IRC, and Facebook at no cost per message from your Windows Phone 7 Device." +
                        "\n\nThanks.";
                    emailTask.Show();
                    break;
                case "1":                    
                    wbt.Uri = new Uri("http://www.facebook.com/296776117006463");
                    wbt.Show();
                    break;
                case "2":
                    wbt.Uri = new Uri("http://www.twitter.com/groovyim");
                    wbt.Show();
                    break;
            }
        }

        private void runLocked_Checked(object sender, RoutedEventArgs e)
        {
            App.runUnderLocked(true);
        }

        private void runLocked_Unchecked(object sender, RoutedEventArgs e)
        {
            App.runUnderLocked(false);
        }

        private void confirmExit_Checked(object sender, RoutedEventArgs e)
        {
            App.confirmExit = true;
        }

        private void confirmExit_Unchecked(object sender, RoutedEventArgs e)
        {
            App.confirmExit = false;
        }
    }
}